import random
import turtle as tl

# the acute angle between
# the base and branch of the Y
angle = 30

# function to plot a Y
def draw_tree(sz, level):
    if level == 0:
        return

    # splitting the rgb range for green
    # into equal intervals for each level
    # setting the colour according
    # to the current level
    tl.pencolor(0, 255 // level, 0)
    tl.pensize(level)

    # drawing the base
    tl.fd(sz)

    a1 = angle + (random.random()*2 - 1)*10
    tl.rt(a1)

    # recursive call for
    # the right subtree
    draw_tree(0.8 * sz, level - 1)

    tl.pencolor(0, 255 // level, 0)
    a2 = angle + (random.random()*2 - 1)*10
    tl.lt(a1+a2)

    # recursive call for
    # the left subtree
    draw_tree(0.8 * sz, level - 1)

    tl.pencolor(0, 255 // level, 0)

    tl.rt(a2)
    tl.fd(-sz)

def draw():
    tl.speed('fastest')
    tl.colormode(255)

    # turning the turtle to face upwards
    tl.rt(-90)

    # tree of size 80 and level 7
    draw_tree(80, 8)


if __name__ == "__main__":
    draw()

    # wait end
    tl.mainloop()